/*
 * Copyright 2014 OGIS-RI All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jp.co.ogis_ri.optaplanner.vehiclerouting.domain.core;

import org.apache.commons.lang3.builder.CompareToBuilder;
import org.optaplanner.core.api.score.constraint.ConstraintMatch;

import java.io.Serializable;

public abstract class AbstractPersistable implements Serializable,
		Comparable<AbstractPersistable> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * ID
	 */
	protected Long id;

	/**
	 * 
	 */
	protected AbstractPersistable() {
	}

	/**
	 * 
	 * @return
	 */
	public Long getId() {
		return this.id;
	}

	/**
	 * 
	 * @param id
	 */
	public void setId(final Long id) {
		this.id = id;
	}

	/**
	 * Used by the GUI to sort the {@link ConstraintMatch} list by
	 * {@link ConstraintMatch#getJustificationList()}.
	 * 
	 * @param other
	 *            never null
	 * @return comparison
	 */
	@Override
	public int compareTo(final AbstractPersistable other) {
		return new CompareToBuilder()
				.append(this.getClass().getName(), other.getClass().getName())
				.append(this.id, other.id).toComparison();
	}

	/**
	 * 
	 */
	@Override
	public String toString() {
		return "[" + this.getClass().getName().replaceAll(".*\\.", "") + "-"
				+ this.id + "]";
	}

}
